package ute.mvc.util;

public class IdUtil {
	/**
	 * 
	 * @param maxQuestionId
	 * regex SubjectId_PoolId_QuestionId
	 * @return newId
	 */
	public static String getNewQuestionIdInPool(String maxQuestionId) {
		String nextId = null;
		String currentId = null;
		String[] ids = null;
		if (maxQuestionId == null) {
			return "001";
		} else {
			ids = maxQuestionId.split("_");
		}

		currentId = ids[ids.length - 1];
		int num = Integer.parseInt(currentId) + 1;
		// regex ###
		nextId = String.format("%03d", num);
		return nextId;
	}
	
	public static String getNewQuestionPoolIdInSubject(String maxQuestionPoolId) {
		String nextId = null;
		String currentId = null;
		String[] ids = null;
		if (maxQuestionPoolId == null) {
			return "001";
		} else {
			ids = maxQuestionPoolId.split("_");
		}

		currentId = ids[ids.length - 1];
		int num = Integer.parseInt(currentId) + 1;
		// regex ###
		nextId = String.format("%03d", num);
		return nextId;
	}
	
	public static String getNewTestIdInOpenCourseSubject(String maxId) {
		String nextId = null;
		String currentId = null;
		String[] ids = null;
		if (maxId == null) {
			return "001";
		} else {
			ids = maxId.split("_");
		}

		currentId = ids[ids.length - 1];
		int num = Integer.parseInt(currentId) + 1;
		// regex ###
		nextId = String.format("%03d", num);
		return nextId;
	}
	
	public static String getNewPartIdInTest(String maxId) {
		String nextId = null;
		String currentId = null;
		String[] ids = null;
		if (maxId == null) {
			return "001";
		} else {
			ids = maxId.split("_");
		}

		currentId = ids[ids.length - 1];
		int num = Integer.parseInt(currentId) + 1;
		// regex ###
		nextId = String.format("%03d", num);
		return nextId;
	}
	
	public static String getNextId(String maxId) {
		String nextId = null;
		String currentId = null;
		String[] ids = null;
		if (maxId == null) {
			return "001";
		} else {
			ids = maxId.split("_");
		}

		currentId = ids[ids.length - 1];
		int num = Integer.parseInt(currentId) + 1;
		// regex ###
		nextId = String.format("%03d", num);
		return nextId;
	}
}
